package game.gfx;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageReader
{
	public int width;
	public int height;
	private int argb;
	private int[] rgb;
	private String path;
	public String[][] pixelData;
	
	public ImageReader(String path)
	{
		BufferedImage image = null;
		String workingDir = System.getProperty("user.dir");
		
		try
		{
			this.path = path;
			File imagefile = new File(workingDir + path);
			image = ImageIO.read(imagefile);			
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}

		this.width = image.getWidth();
		this.height = image.getHeight();
					
		this.pixelData = new String[width][height];		
		
		for (int y = 0; y < height; y++)
		{
			for (int x = 0; x < width; x++)
			{
				argb = image.getRGB(x, y);
				rgb = new int[] {(argb >> 16) & 255, (argb >> 8)  & 255, (argb) & 255};
				pixelData[x][y] = String.format("%03d", rgb[0]) + String.format("%03d", rgb[1]) + String.format("%03d", rgb[2]);			
			}
		}		
	}
	
	public String[][] getPixelData()
	{
		return pixelData;
	}
	
	public int getWidth()
	{
		return width;
	}
	
	public int getHeight()
	{
		return height;
	}
}
